//自己手动实现栈

import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;

    //创建栈的容器
    public MyStack(){
        this.elem = new int[10];
    }

    //压栈
    public void push(int val){
        if(isFull()){
            //扩容
            elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize] = val;
        usedSize ++;
    }

    //出栈
    public int pop(){
        if(empty()){
            return -1;
        }
        int oldVal = elem[usedSize - 1];
        usedSize --;
        return oldVal;
    }

    //获取栈顶元素
    public int peek(){
        if(empty()){
            return -1;
        }
        return elem[usedSize - 1];
    }

    //判断栈是否为空
    public boolean empty(){
        return usedSize == 0;
    }

    //判断栈是否满了
    public boolean isFull(){
        return usedSize == elem.length;
    }
}
